Ext.QuickTips.init(false);
// Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Hxcy = {
	CPT : "/zuoyue",
	emptyFn : function() {
		Ext.MessageBox.show({
			title : '提示信息',
			msg : "<br />此功能暂时未能实现",
			buttons : Ext.MessageBox.OK,
			icon : Ext.MessageBox.INFO
		});
	}
};
//Ext.BLANK_IMAGE_URL = Hxcy.CPT + '/scripts/ext2.2.1/resources/images/default/s.gif';
Ext.BLANK_IMAGE_URL = Hxcy.CPT + '/js/ext-3.0.3/resources/images/default/s.gif';

Ext.ns( "Hxcy.Ajax", "Hxcy.main.fgys", "Hxcy.main.site" ,
		"Hxcy.main.youhua","Hxcy.main.tousu", "Hxcy.main.pucha", "Hxcy.main.wuye", "Hxcy.main.quyewu");
Hxcy.Util = function() {
	return {
		/**
		 * 递归的复制属性
		 */
		applyIf : function(dest, source) {
			for (var p in source) {
				if (typeof dest[p] == "undefined") {// 测试在表单配置是否有此成员
					dest[p] = source[p];// 没有则添加
				} else if (typeof dest[p] == "object") {// 有则测试其是不是一个对象
					this.applyIf(dest[p], source[p]);
				}
			}
		},
		/**
		 * 对一个对象的所有属性进行列表,将属性名与属性值一次性显示出来
		 */
		list : function(o, all) {
			var v = "";
			for (var p in o) {
				// typeof o[p] == "object" ? v += this.list(o[p]) : v += "属性:" +
				// p + "值:" + o[p];
				if(all){
					typeof o[p] == "object" || typeof o[p] == "function" ? "" : v += "属性:" + p + "值:" + o[p];
				} else {
					v += "属性:" + p + "值:" + o[p];
				}
			}
			return v;
		},
		/**
		 * 主要将基础配置中的属性复制到一个具体配置中,但这里是获取配置,所以只在第一次进行复制,以后就是直接返回
		 */
		cfg : function(subConfig, baseConfig) {
			if (!subConfig || !baseConfig) {
				alert("在配置属性进行复制的时候,目标与源都不能为空");
			}
			if (!subConfig.init) {
				Hxcy.Util.applyIf(subConfig, baseConfig);
				subConfig.init = true;
			}
			return subConfig;
		},
		msg : function(msg, cb) {
			Ext.MessageBox.show({
				title : '消息',
				msg : "<br />" + msg,
				buttons : Ext.Msg.OK,
				icon : Ext.Msg.INFO,
				fn : cb || Ext.emptyFn
			});
		},
		error : function(msg, cb) {
			Ext.MessageBox.show({
				title : '消息',
				msg : "<br />" + msg,
				buttons : Ext.Msg.OK,
				icon : Ext.Msg.ERROR,
				fn : cb || Ext.emptyFn
			});
		}
	}
}();

Hxcy.TPL = {
	form : {
		xtype : 'form',
		//defaultType : 'textfield',
		layoutConfig : {// 专有布局配置
			labelWidth : 75,
			labelPad : 20,// 标签内边距
			labelAlign : "left",
			labelSeparator : '：'
		},
		defaults : {// 应用于所有子组件的公共配置
			width : 240,
			validateOnBlur : false,// 这里阻止客户端检验的表象效果发生,而最终是否校验决定于最后提交时的选项
			validationEvent : false,
			msgTarget : 'side'
		},
		border : false,
		bodyStyle : 'padding:10px;',
		listeners : {
			actioncomplete : function(form, action) {
				var result = action.result;// 这是返回的结果对象
				if (result.success) {
					Hxcy.Util.msg(result.messages);
				} else {
					Hxcy.Util.error(result.actionErrors[0] ? result.actionErrors : '操作失败');
				}
			},
			actionfailed : function(form, action) {
				var result = action.result;// 这是返回的结果对象
				Hxcy.Util.error(result&&result.actionErrors[0] ? result.actionErrors : '操作失败');
				// alert(action.response.responseText);
			},
			beforeaction : function(form, action) {
				form.clearInvalid();
			}
		}
	}
};

Ext.apply(Hxcy.Ajax, Ext.lib.Ajax);
Hxcy.Ajax.hasHeaders = true;
Hxcy.Ajax.headers = {"If-Modified-Since":"0"};
Hxcy.Ajax.syncRequest = function(method, uri, callback, postData, options){
	var o = this.getConnectionObject();
    if (!o) {
        return null;
    }
    else {
        o.conn.open(method, uri, false);

        if (this.useDefaultXhrHeader) {
            if (!this.defaultHeaders['X-Requested-With']) {
                this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
            }
        }

        if(postData && this.useDefaultHeader && (!this.hasHeaders || !this.headers['Content-Type'])){
            this.initHeader('Content-Type', this.defaultPostHeader);
        }

         if (this.hasDefaultHeaders || this.hasHeaders) {
            this.setHeader(o);
        }

        o.conn.send(postData || null);
        this.handleTransactionResponse(o, callback);
        return o;
    }
};

Ext.Ajax.on('requestcomplete',function checkUserSessionStatus(conn,response,options){
	if (!response.getResponseHeader) {
		return;
	}
    //Ext重新封装了response对象   
    if(typeof response.getResponseHeader.sessionstatus != 'undefined'){   
        //发现请求超时，退出处理代码...
    	Hxcy.Util.error("由于长时间没有与服务器联系或者服务器已经重启,登录已经失效,请重新登录", function(){
    		top.location="/vehms/public/login.jsp";		
    	});
    }   
    if(typeof response.getResponseHeader.securitystatus != 'undefined'){   
    	Hxcy.Util.error("你访问的资源或执行的操作是受保护的,<br />而你没有相应的授权,如需要执行请与管理员联系");
    }   
} );   

Hxcy.Factory = function(config){
	config = config || {};
	if (typeof config == "string") {
		config = {ns : config};
	}
	Ext.apply(this, config);
	if (this.ns) {
		this.setNS(this.ns);
	}
	this.idCounter = 1000;
	this.ComponetContainer = {};
	this.dictReader = [{
			name : 'dictId',
			mapping : 'dictId',
			type : 'int'
		}, {
			name : 'itemTitle',
			mapping : 'itemTitle'
		}]
}

Hxcy.Factory.prototype = {
	EmptyStore : new Ext.data.Store({url:true}),
	createUrl : function(url){
		return url.indexOf('/')==0? url:this.nspath+url;
	},
	setNS : function(ns){
		this.ns = ns;
		this.NS = eval('(' + this.ns + ')');
		this.nspath = Hxcy.CPT+"/"+this.ns.replace(/\./g, "/").toLowerCase()+"/";
		this.prefix = this.ns.replace(/\./g, "-").toLowerCase()+"-";
	},
	setCombo : function(comboId, rd, key){
		var combo = Ext.getCmp(comboId);
		if(combo){
			key = key || rd.get(combo.valueField);
			rd = rd || this.EmptyStore.getAt(0);
			this.EmptyStore.removeAll();
			this.EmptyStore.add(rd);
			combo.setValue(key);
		} else {
			alert('指定的comboId不是一个组件combo组件ID');
		}
	},
	setDataView : function(record, remote){
		if (remote) {
			this.EmptyStore.reader = remote.reader||remote.store.reader;
			var url = remote.url || remote.store.proxy.conn.url;
			url = this.createUrl(url);
			this.EmptyStore.proxy.conn.url = url;
			this.EmptyStore.recordType = remote.recordType||remote.store.recordType;
			this.EmptyStore.load({
				params : remote.params||{},
				callback : remote.callback
			});
		} else {
			this.EmptyStore.removeAll();
			this.EmptyStore.add(record);
		}
	},
	reset : function(record, remote){
		this.EmptyStore.removeAll();
		if (record) {
			this.EmptyStore.add(record);
		} else if (remote) {
			this.EmptyStore.reader = remote.reader||remote.store.reader;
			var url = remote.url || remote.store.proxy.conn.url;
			url = this.createUrl(url);
			this.EmptyStore.proxy.conn.url = url;
			this.EmptyStore.recordType = remote.recordType||remote.store.recordType;
			this.EmptyStore.load({
				params : remote.params||{},
				callback : remote.callback
			});
		} 
	},
	put : function(name, comp){
		this.ComponetContainer[name] = comp;
	},
	get : function(name){
		return this.ComponetContainer[name];
	},
	putNS : function(space){
		space = typeof space=='string' ? [space] : space;
		var ns = this.NS;
		for (var index = 0; index < space.length; index++) {
			var spaceCases = space[index].split('.');
			var o = ns;
			for (var caseIndex = 0; caseIndex < spaceCases.length; caseIndex++) {
				o = o[spaceCases[caseIndex]];
			}
			for(var p in o){
				this.ComponetContainer[p]=o[p];
			}
		}
	},
	createRecord : function(fields, values){//简单创建一个临时的记录
		var Record = Ext.data.Record.create(fields);
		var temp = {};
		for(var i=0; i<fields.length; i++){
			temp[fields[i]]=values[i];
		}
		return new Record(temp);
	},
	createCombo : function(cfg){
		cfg = typeof cfg=='string' ? {hiddenName:cfg} : cfg;
		cfg.space = cfg.space || 'formfields-';
		cfg.fieldLabel = cfg.fieldLabel || '';
		var id = this.createComboId(cfg);
		var base = {
			id : id,
			fieldLabel : cfg.hiddenName,
			xtype: 'combo',
			readOnly : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			valueField : cfg.hiddenName,
			displayField : cfg.hiddenName+'Title',
			store: this.EmptyStore,
			//emptyText : '请选择'+cfg.fieldLabel+'...'
			emptyText : '请选择...'
		};
		Ext.applyIf(cfg, base);
		return cfg;
	},
	createCombo2 : function(cfg){
		cfg = typeof cfg=='string' ? {hiddenName:cfg} : cfg;
		cfg.space = cfg.space || 'formfields-';
		cfg.fieldLabel = cfg.fieldLabel || '';
		var id = this.createComboId(cfg);
		var base = {
			id : id,
			fieldLabel : cfg.hiddenName,
			xtype: 'combo',
			readOnly : true,
			editable : false,
//			allowBlank : false,
			triggerAction : 'all',
			valueField : cfg.hiddenName,
			displayField : cfg.hiddenName+'Title',
			store: this.EmptyStore,
			emptyText : '请选择...'
		};
		Ext.applyIf(cfg, base);
		return cfg;
	},
	createComboId : function(cfg){
		cfg = typeof cfg=='string' ? {hiddenName:cfg} : cfg;
		cfg.space = cfg.space || 'formfields-';
		return this.prefix+cfg.space+cfg.hiddenName.toLowerCase()+'-combo-'+this.idCounter++;
	},
	createDictCombo : function(cfg){
		cfg.valueField = 'dictId';
		cfg.displayField = 'itemTitle';
		cfg.store = this.createDictStore(cfg.groupName||cfg.fieldLabel);
		return this.createCombo(cfg);
	},
	createDictCombo2 : function(cfg){
		cfg.valueField = 'itemTitle';
		cfg.displayField = 'itemTitle';
		cfg.store = this.createDictStore(cfg.groupName||cfg.fieldLabel);
		return this.createCombo2(cfg);
	},
	createPagingToolbar : function(cfg){
		cfg = cfg.store ? cfg : {store : cfg};
		Ext.applyIf(cfg, {
			pageSize : 20,
			paramNames : {
				start : 'page.start',
				limit : 'page.limit'
			},
			displayInfo : true,
			displayMsg : '第{0}条 - 第{1}条 共{2}条',
			emptyMsg : "没有可显示的记录"
		});
		return new Ext.PagingToolbar(cfg);
	},
	createSM : function(single){
		if(single==='undefined'){
			single = true;
		}
		return new Ext.grid.CheckboxSelectionModel({singleSelect:single});
	},
	createCM : function(cfg){
		if (typeof cfg=='string') {
			cfg = {beanName : cfg};
		}
        
		var ns = cfg.ns ? eval('(' + cfg.ns + ')') : this.NS;
		var noappend = cfg.noappend===false;
		var sm = cfg.sm || cfg.beanName+'SM'
		var mapping = cfg.mapping || cfg.beanName+'Mapping'
		
		if (typeof sm=='string') {
			sm = ns.SM[sm]||this.get(sm);//因为一些空间变量可能会被重新定义,此时以前在此空间下的定义就不存在,但它应该会在工厂容器中
		}
		if (typeof mapping=='string'){
			mapping = ns.Mapping[mapping]||this.get(mapping);
		}
		
		if (!noappend) {
			mapping = [sm].concat(mapping);
		}
		return  new Ext.grid.ColumnModel(mapping);
	},
	createStore : function(cfg){
		cfg.url = this.createUrl(cfg.url);
		var ns = cfg.ns ? eval('(' + cfg.ns + ')') : this.NS;
		var reader = cfg.reader||cfg.beanName+'Reader';
		if (typeof reader=='string') {
			reader = ns.Reader[reader]||this.get(reader);//因为一些空间变量可能会被重新定义,此时以前在此空间下的定义就不存在,但它应该会在工厂容器中
		}
        cfg.fields = reader;
        var baseCfg = {
            root : 'records',
            totalProperty : 'totalCount',
            remoteSort:true
        };
        Ext.applyIf(cfg, baseCfg);
		return new Ext.data.JsonStore(cfg);
	},
	createDictStore : function(groupName){
		var reader = this.dictReader;
		return new Ext.data.JsonStore({
			url : Hxcy.CPT+'/public/listItemsByGroupName.action',
			root : 'records',
			totalProperty : 'totalCount',
			autoLoad : true,
			baseParams : {groupName:groupName},
			fields : reader
		});
	},
	createDataView : function(cfg){
		cfg = typeof cfg=='string' ? {beanName:cfg} : cfg;
		var store = cfg.store ||this.EmptyStore;
		delete cfg.store;
		var ns = cfg.ns ? eval('(' + cfg.ns + ')') : this.NS;
		var viewName = cfg.viewName || cfg.beanName+'TPL';
		delete cfg.viewName;
		var viewTPL = ns.ViewTPL[viewName]||this.get(viewName);
		var title = cfg.title || '视图标题';
		delete cfg.title;
		var id = this.prefix + viewName + this.idCounter++;
		baseCfg = {
			id : id,
			xtype : 'panel',
            cls : 'dataview-panel',
			layout : 'ux.center',
			border : false,
			title : title,
			//bodyStyle : 'background: #FDF5E6',//#dfe8f6;
			winCfg : {
				btn0 : false,
				title : title
			},
			items : {
				xtype : 'dataview',
				store : store,
				itemSelector : 'div.dataview-wrap',
				loadingText : '正在加载数据...',
				emptyText : '没有查找到相关数据或关联视图',
				width : '90%',
				tpl :  viewTPL
			}
		};
		Hxcy.Util.applyIf(cfg, baseCfg);
		return cfg;
	},
	createUnitTree : function(cfg){
		cfg = typeof cfg=='string' ? {comboId:cfg} : cfg;
		cfg.comboId = cfg.id||cfg.comboId||this.createComboId(cfg);
		var setCombo = this.setCombo;
		var createRecord = this.createRecord;
		var factory = this;
		var id = 'vehms-public-unit-tree-'+cfg.comboId;
		if (this.get(id)) {
			return this.get(id);
		}
		var tree = {
			id : id,
			bodyStyle : 'padding:10px;',
			rootVisible : false,
			layoutConfig : {
				animate : true
			},
			defaults : {
				border : false
			},
			xtype : 'treepanel',
			border : false,
			autoScroll : true,
			root : {
				nodeType : 'async',
				text : '单位根',
				unitId : 0,
				uiProvider : Ext.tree.RootTreeNodeUI
			},
			checkModel : 'single',
			winCfg : {
				width : 300,
				btn0 : false,
				btn1Handler : cfg.handler || function(){
					var tree = this[id].getSource();
					var ids = tree.getChecked('unitId').join(',');
					var texts = tree.getChecked('text').join(',');
					
					if (ids && texts) {
						var rd = createRecord.call(factory, [cfg.valueField||'unitId',cfg.displayField||'unitName'],[ids, texts]);
						setCombo.call(factory, cfg.comboId, rd, ids);
						if(cfg.callback){
							cfg.callback(cfg.comboId, rd, ids, texts);
						}
					}
					Hxcy.CmpMgr.hideWindow();
				}
			},
			loader : new Ext.tree.TreeLoader({
				dataUrl : Hxcy.CPT + '/public/listUnitTreeNode.action',
				baseAttrs : {
					uiProvider : Ext.ux.TreeCheckNodeUI
				},
				listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.unitId = node.attributes.unitId||0;
					},
					load : function(loader, node, response) {
						// alert("加载的数据:" + response.responseText);
					},
					loadexception : function(loader, node, response) {
						alert("异常:" + response.statusText);
					}
				}
			}),
			listeners : {
				render : function(tree){
					var ctx = new Hxcy.PageContext(tree, id);
					ctx.registerWnd();
				}
			}
		};
		this.put(id, tree);
		return tree;
	}
}

Hxcy.PageContext = function(source, ctxName){
	this.source = source;
	this.ctxName = ctxName;
}

Hxcy.PageContext.prototype = {
	registerMenu : function(menu){
		if (typeof reader=='string') {
			menu = Ext.menu.MenuMgr.get(menu);
		}
		var items = menu.items;
		items.each(function(item){
			if(item.text!='undefined'){
				item[this.ctxName]=this;
			}
		}, this)
	},
	registerForm : function(fp){
		var cpt = Ext.getCmp(fp.id);
		if (cpt) {
			cpt.getForm()[this.ctxName] = this;
		} else {
			fp.initialConfig = fp.initialConfig || {};
			fp.initialConfig[this.ctxName] = this;//注意此配置将会进行BasicForm
			fp[this.ctxName] = this;
			Ext.apply(fp.initialConfig, fp);//注意配置initialConfig则fp中的配置会失效,所以此处有这样的操作
		}
	},
	register : function(component){
		var cpt = Ext.getCmp(component.id)||component;
		cpt[this.ctxName] = this;
	},
	registerWnd : function(){
		Hxcy.CmpMgr.registerBtnCtx(this);
	},
	getSource : function(){
		return this.source;
	}
}

Hxcy.GridContext = function(grid, ctxName){
	this.grid=grid;
	ctxName = ctxName||grid.id
	Hxcy.GridContext.superclass.constructor.call(this, grid, ctxName);
}
Ext.extend(Hxcy.GridContext, Hxcy.PageContext, {
	getGrid : function(){
		return this.grid;
	},
	
	getStore : function(){
		return this.grid.store;
	},
	
	reload : function(options){
		options = options || {};
		if (options.url) {
			this.setTarget(options.url);
		}
		return this.grid.store.reload(options);
	},
	
	load : function(options){
		if (options.url) {
			this.setTarget(options.url);
		}
		return this.grid.store.load(options);
	},
	
	setTarget : function(url){
		this.grid.store.proxy.conn.url = url;
	},
	
	getTarget : function(){
		return this.grid.store.proxy.conn.url;
	},
	
	getSM : function(){
		return this.grid.selModel;
	},
	getCM : function(){
		return this.grid.colModel;
	},
	getSelected : function(){
		return this.grid.selModel ? this.grid.selModel.getSelected() : null;
	},
	
	selectRow : function(e){//根据上下文事件来选择表格行
		if (e.getTarget) {
			var row = this.grid.view.findRowIndex(e.getTarget());
			if (row!==false) {
				this.grid.selModel.selectRow(row);
			}
		} else if(typeof e=='number'){
			this.grid.selModel.selectRow(e);//记录索引
		} else if(typeof e=='object'){
			this.grid.selModel.selectRecords([e]);
		} else if(Ext.isArray(e)){
			this.grid.selModel.selectRows(e);//记录索引
		}
		return this.getSelected();
	},
	
	activeContextMenu : function(cfg){
		cfg.menu.items.each(function(item){
			cfg.callback(item);
		}, cfg.scope||this);
		if(cfg.e){
			cfg.menu.showAt(cfg.e.getXY());
			cfg.e.stopEvent();
		}
	},
	
	activeCtxMenuDependOne : function(cfg){
		cfg.group = cfg.group ||'depend-one';
		var rd = cfg.e ? this.selectRow(cfg.e) : this.getSelected();
		cfg.callback = function(item){
			(item.group==cfg.group && !rd || item.originDisabled) ? item.disable() : item.enable();
		}
		this.activeContextMenu(cfg);
	}
});

Hxcy.FormContext = function(fp, ctxName){
	this.fp = fp;
	ctxName = ctxName || fp.id;
	Hxcy.FormContext.superclass.constructor.call(this, fp, ctxName);
};
Ext.extend(Hxcy.FormContext, Hxcy.PageContext, {
	getForm : function(){
		return this.fp.getForm();
	},
	
	loadRecord : function(record){
		this.fp.getForm().loadRecord(record)
	},
	
	setUrl : function(url){
		this.fp.getForm().url = url;
	},
	
	findField : function(fieldName){
		return this.getForm().findField(fieldName);
	},
	
	setValues : function(values){
		this.getForm().setValues(values);
	},
	
	setDisabled : function(config){
		var form = this.getForm();
		form.items.each(function(field){
			if(field.group){
				if(field.group.indexOf(config.groupName)>=0){
					field.setDisabled(config.disabled);
					if(field.wrap){
						config.disabled ? field.wrap.addClass('x-item-disabled') : field.wrap.removeClass('x-item-disabled');
					}
					if (config.cls) {
						var item = field.getEl().parent('div.x-form-item');
						config.disabled? item.removeClass(config.cls):item.addClass(config.cls);
					}
				} else if(config.other){
					field.setDisabled(!config.disabled);
					if(field.wrap){
						!config.disabled ? field.wrap.addClass('x-item-disabled') : field.wrap.removeClass('x-item-disabled');
					}
				}
			}
		});
	},
	setVisible : function(b, fields){
		fields = typeof fields=='string' ? [fields] : fields;
		for (var index = 0; index < fields.length; index++) {
			var field = this.findField(fields[index]);
			var item = field.getEl().parent('div.x-form-item');
			item.setVisibilityMode(Ext.Element.DISPLAY);
			item.setVisible(b);
		}
	},
	reset : function(record){
		this.fp.getForm().reset();
		if (record) {
			this.loadRecord(record);
		}
	}
});

function obj2str(o){
    var r = [];
    if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
    if(typeof o == "object"){
        if(!o.sort){
            for(var i in o)
                r.push(i+":"+obj2str(o[i]));
            if(!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)){
                r.push("toString:"+o.toString.toString());
            }
            r="{"+r.join()+"}"
        }else{
            for(var i =0;i<o.length;i++)
                r.push(obj2str(o[i]))
            r="["+r.join()+"]"
        }
        return r;
    }
    return o.toString();
}

Ext.ux.ComboBoxTree = function(){
	this.treeId = Ext.id()+'-tree';
//	this.maxHeight = arguments[0].maxHeight || arguments[0].height || this.maxHeight;
	this.maxHeight = 200;
	this.tpl = new Ext.Template('<tpl for="."><div style="height:'+this.maxHeight+'px"><div id="'+this.treeId+'"></div></div></tpl>');
	this.store = new Ext.data.SimpleStore({fields:[],data:[[]]});
	this.selectedClass = '';
	this.mode = 'local';
	this.triggerAction = 'all';
	this.onSelect = Ext.emptyFn;
	this.editable = false;
	
	//需要设置多个字段的值时，需要的字段id
	this.otherFieldId='';
	
	this.isHiddenvalue=false;
	//all:所有结点都可选中
	//exceptRoot：除根结点，其它结点都可选
	//folder:只有目录（非叶子和非根结点）可选
	//leaf：只有叶子结点可选
	this.selectNodeModel = arguments[0].selectNodeModel || 'exceptRoot';
	
	Ext.ux.ComboBoxTree.superclass.constructor.apply(this, arguments);
}

Ext.extend(Ext.ux.ComboBoxTree,Ext.form.ComboBox, {
	
	expand : function(){
		Ext.ux.ComboBoxTree.superclass.expand.call(this);
		if(this.tree.xtype == 'treepanel'){
			if(!this.tree.rendered){
				this.tree.height = this.maxHeight;
				this.tree.border=false;
				this.tree.autoScroll=true;
		        if(this.tree.xtype){
					this.tree = Ext.ComponentMgr.create(this.tree, this.tree.xtype);
				}
				this.tree.render(this.treeId);
					
		        var combox = this;
		        this.tree.on('click',function(node){
		        	var isRoot = (node == combox.tree.getRootNode());
		        	var selModel = combox.selectNodeModel;
		        	var isLeaf = node.isLeaf();
		        	if(isRoot && selModel != 'all'){
		        		return;
		        	}else if(selModel=='folder' && isLeaf){
		        		return;
		        	}else if(selModel=='leaf' && !isLeaf){
		        		return;
		        	}
		        	combox.setValueNode(node);
		        	combox.collapse(); 
		        });
				var root = this.tree.getRootNode();
				if(!root.isLoaded())
					root.reload();
			}
		}else{
			Hxcy.Util.msg("<font color='red'>请选择服务类型</font>");
			this.collapse();
		}
    },
    
	setValueNode : function(node){
		//这里最好能node里面的属性递归出来,node里面有多少个变量就动态定义变量
        var text = node.attributes.text;
        var itemsID=node.attributes.itemsID;
        var foodPrice = node.attributes.foodPrice;
        var foodAmount = node.attributes.foodAmount;
        var ticketPrice = node.attributes.ticketPrice;
        this.lastSelectionText = text;
        if(this.hiddenField){
            this.hiddenField.value = this.isHiddenvalue ? itemsID : text;  
        }
        Ext.form.ComboBox.superclass.setValue.call(this, text); 
        
        for(var fieldCount = 0; fieldCount < this.otherFieldId.length; fieldCount++ ){
        	 var _fieldid = Ext.getCmp(this.otherFieldId[fieldCount]);
	         switch(obj2str(this.otherFieldId[fieldCount])){
	         	case '"foodPrice"' :  _fieldid.setValue(foodPrice);
	         		break;
	         	case '"foodAmount"' :  _fieldid.setValue(foodAmount);
	         		break;
	         	case '"ticketPrice"' : _fieldid.setValue(ticketPrice);
	         		break;
	         	//这里对应的是动态添加的常规服务信息
	         	default : _fieldid.setValue(ticketPrice);
	         }
        }
	    this.value= text;
    },
    
    setValue : function(v){
		var text = v;
		if(this.valueField){
			var r = this.findRecord(this.valueField, v);
			if(r){
				text = r.data[this.displayField];
			}
		}
		this.lastSelectionText = text;
		if(this.hiddenField){
			this.hiddenField.value = v;
		}
		text = text=='null' ? '' : text;
		Ext.form.ComboBox.superclass.setValue.call(this, text);
		this.value = v;
		return this;
	}/*,
    
    getValue : function(){
    	return typeof this.value != 'undefined' ? this.value : '';
    }*/
});

Ext.reg('combotree', Ext.ux.ComboBoxTree);

Hxcy.SearchForm = Ext.extend(Ext.form.FormPanel, {
	initComponent :function(){
		Hxcy.SearchForm.superclass.initComponent.call(this);
		/*this.on('specialkey',function(f,e){
			if(e.getKey() == e.ENTER){
				this.submit();
			}
		},this)*/
	},
	submit : function(options){
		options = options || {};
		options.params = options.params||{};
		var formParams = this.getForm().getValues();
		
		if(this.bind===true){
			Ext.apply(this.store.baseParams, formParams);
		} else {
			Ext.applyIf(options.params, formParams);
		}
		Hxcy.Util.cfg(options, this.store.lastOptions);
		
		this.store.reload(options);
	},
	reset : function(options){
		options = options || {};
		options.params = options.params||{};
		this.getForm().reset();
		var formParams = this.getForm().getValues();
		if(this.bind===true){
			var formParams = this.getForm().getValues();
			for(var name in formParams){
				delete this.store.baseParams[name];
			}
		}
		Ext.applyIf(options.params, formParams);
		Hxcy.Util.cfg(options, this.store.lastOptions);
		for(var f in formParams){
			var v = this.getForm().findField(f).getValue();
			if(Ext.isEmpty(v)){//如果不空值则不向后台传值,因为由于转换器的原因传空值有可能变成false
				delete options.params[f];
			}
		}
		this.store.reload(options);
	}
});
Ext.reg('searchform', Hxcy.SearchForm);